using System;
using System.Globalization;

namespace PickGold.Charting.Design
{
	internal class AnnotationCollectionEditor : ChartCollectionEditor
	{
		public AnnotationCollectionEditor()
			: base(typeof(AnnotationCollection))
		{
		}

		protected override object CreateInstance(Type itemType)
		{
			Chart chartReference = (Chart)ChartCollectionEditor.GetChartReference(base.Context.Instance);
			Annotation annotation = base.CreateInstance(itemType) as Annotation;
			if (chartReference != null)
			{
				annotation.Name = NextUniqueName(chartReference, itemType);
			}
			return annotation;
		}

		protected override Type[] CreateNewItemTypes()
		{
			return new Type[] { typeof(LineAnnotation), typeof(VerticalLineAnnotation), typeof(HorizontalLineAnnotation), typeof(TextAnnotation), typeof(RectangleAnnotation), typeof(EllipseAnnotation), typeof(ArrowAnnotation), typeof(Border3DAnnotation), typeof(CalloutAnnotation), typeof(PolylineAnnotation), typeof(PolygonAnnotation), typeof(ImageAnnotation), typeof(AnnotationGroup) };
		}

		private static string NextUniqueName(Chart control, Type type)
		{
			string name = string.Empty;
			string str2 = type.Name;
			for (int i = 1; i < 0x7fffffff; i++)
			{
				name = str2 + i.ToString(CultureInfo.InvariantCulture);
				if (control.Annotations.IsUniqueName(name))
				{
					return name;
				}
			}
			return name;
		}
	}
}

